<template>
	<view class="content">
		<!-- usearch -->
		<uni-search-bar @confirm="doSearch" v-model="key" />
		<swiper style="height: 200px;" indicator-active-color="#ff6700" indicator-color="#fff" :indicator-dots="true"
			:autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in bannerGoodsList" :key="index">
				<view class="swiper-item">
					<image :src="item.goods_big_logo" style="width: 100%;" mode="widthFix"></image>
				</view>
			</swiper-item>
		</swiper>
		<view class="cateList">
			<view class="item" v-for="(item,index) in cateOneLst" :key ="index">
				<view class="logo">
					<image :src="item.icon" mode=""></image>
				</view>
				<view class="name">{{item.name}}</view>
			</view>
		</view>
		<view class="title">精选商品</view>
		<view class="selectList">
		<view class="item" v-for="(item,index) in selectedLst" :key="index">
			<view class="pic">
				<image :src="item.goods_big_logo" mode=""></image>
			</view>
			<view class="name">{{item.name}}</view>
			<view class="msg">
				<view class="price">￥{{item.price}}</view>
				<view class="tag">精选</view>
			</view>
		</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	let bannerGoodsList = ref([])
	let key = ref("")
	onLoad(() => {
		getBanner()
		getCateOneLst()
		getSelectedList()
	})

	function doSearch() {
		uni.showToast({
			title: key.value,
		})
	}
	async function getBanner() {
	
		
		let res = await uni.$post("/goodsPromoteSelect", {
			"is_selecttd": 1,
			"is_promote": 0,
			"page": 1,
			"number": 20
		})
		if (res.code == 200) {
			console.log(res)
			bannerGoodsList.value = res.goodsList.map(item => {
				item.goods_big_logo = uni.$base_url + item.goods_big_logo
				return item
			})
		}
		// console.log(bannerGoodsList.value)
	}
	
	const cateOneLst = ref([])
	async function getCateOneLst() {
		let res = await uni.$post("/categoryListLevel",{
			"level":0
		})
		if(res.code==200)
		{
			cateOneLst.value=res.result.map(item=>{
				item.icon=uni.$base_url+item.icon
				return item
			})
		}
		console.log(res)
	}
    const selectedLst = ref([])
	async function getSelectedList(){
		let res = await uni.$post("/goodsPromoteSelect", {
			"is_selecttd": 1,
			"is_promote": 0,
			"page": 1,
			"number": 20
		})
		// console.log(res)
		if(res.code == 200){
			selectedLst.value = res.goodsList.map(item => {
				item.goods_big_logo = uni.$base_url + item.goods_big_logo
				return item
			})
		}
		console.log(selectedLst.value)
	}
</script>

<style>
	.cateList{
		margin-top: 10px;
		display: flex;
		justify-content: space-around;
	}
	.cateList>.item>.logo{
		width: 60rpx;
		height: 60rpx;
	}
	.cateList>.item>.logo>image{
		width: 100%;
		height: 100%;
	}
	.cateList>.item.name{
		font-size: 24rpx;
	}
.selectList{
	display: flex;
	flex-wrap: wrap;   
	 justify-content: space-around;
}
.selectList>.item{
	box-sizing: border-box;
	width: 348rpx;
	padding: 15rpx;
	border: 1rpx solid #eee;
	box-shadow: 3px 3px 3px #eee;
}
.selectList>.item>.pic{
	width: 314rpx;
	height: 320rpx;
	border: 1rpx solid #ccc;
	
}
.selectList>.item>.pic>image{
	width: 100%;
	height: 100%;
}
.selectList>.item>.name{
	  overflow: hidden;
	 -webkit-line-clamp: 2;  
	 text-overflow: ellipsis;
	 display: -webkit-box;
	 -webkit-box-orient: vertical;
	 color: #666;
	 font-size: 14px;
}
.selectList>.item>.msg{
	display: flex;
    justify-content: space-between;
}
.selectList>.item>.msg>.price{
	color: #ff6700;
}
.selectList>.item>.msg>.tag{
	background-color: #ff6700;
	color: #fff;
	font-size: 12px;
	padding: 2px 5px;
	border-radius: 5px;
}
</style>